package com.atguigu.day03;

import java.util.concurrent.CountDownLatch;

//减少计数 CountDownLatch
//就是一直减少，直到0才进行的操作（例子：教室有同学在学习，班长必须等教室人数为0，才能关门走人）
public class CountDownLatchDemo {

    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(5);
        for (int i = 1; i <= 5; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName()+"走了。。。");
                //每一个线程执行后，就要减一
                countDownLatch.countDown();

            }, String.valueOf(i)).start();
        }
        //如果上述线程不执行完毕，那就等待
        countDownLatch.await();
        System.out.println(Thread.currentThread().getName()+"关门走人");
    }
}
